<? session_start();
						
include_once ('core/conn.php');
						
$db = get_conn();
						
check_session();
						
if($_GET['id'] != ''){
							
	$sql = " select * from invoices where id_invoice=".$_GET['id']; 
							
	$result = mysql_query($sql);	
							
	if($result){
								
		$row = mysql_fetch_array($result);
		$id_invoice = $row['id_invoice'];
		$id_location = $row['id_location'];
		$id_it = $row['id_it'];
		$amount = $row['amount'];
		$due_date = $row['due_date'];
		$exp_date = $row['exp_date'];
		$description = $row['description'];
		$istatus = $row['istatus'];
							
	}else{
								
		error_handling($sql,mysql_error());
							
	}
						
}
						
						
					
?>
					
					
<html>
					
<head>
<script src="tools/jq_dp/js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="tools/jq_dp/js/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
<link href="http://jqueryui.com/demos/demos.css" rel="stylesheet" type="text/css" />
<script>


function CheckAll(){

	for(i=0;i<document.getElementsByTagName("input").length;i++){
		if(document.getElementsByTagName("input")[i].type == "checkbox"){
			document.getElementsByTagName("input")[i].checked =true;				
		}
	}
}

function UnCheckAll(chk){
	
	
	for(i=0;i<document.getElementsByTagName("input").length;i++){
		if(document.getElementsByTagName("input")[i].type == "checkbox"){
			document.getElementsByTagName("input")[i].checked =false;				
		}
	}
}	


</script>					
<script>
					
<!--
						
	function checkdata(obj){
							
		if(obj.id_it.value ==''){
			alert('Debe seleccionar el tipo de cobro');
			obj.id_it.focus();
			return false;
		}
		
		if(obj.due_date.value ==''){
			alert('Debe seleccionar la fecha de cobro');
			obj.due_date.focus();
			return false;
		}
		
		if(obj.exp_date.value ==''){
			alert('Debe seleccionar la fecha de vencimiento');
			obj.exp_date.focus();
			return false;
		}		
		
		var none_selected = true;
		
		for(i=0;i<document.getElementsByTagName("input").length;i++){
			if(document.getElementsByTagName("input")[i].type == "checkbox"){
				if(document.getElementsByTagName("input")[i].checked ==true){
					none_selected = false;
				}				
			}
		}		
		if(none_selected){
			alert('Debe seleccionar alguna fileal');
			//obj.id_it.focus();
			return false;
		}
							
		


	return true;
						
	}
	

	function show_results(){
		 var itype= document.getElementById('id_it').value;
		 var due_date= document.getElementById('due_date').value;
		 var exp_date= document.getElementById('exp_date').value;	 	 
		 var id_location= document.getElementById('id_location').value;	 	 

	 	 var url = "ajax_comps/history.php?l="+id_location+"&t="+itype+"&d="+due_date+"&e="+exp_date;
		// alert(url);
		$("#list_layer").load(url);	
		 
	 
	}


	$(function() {
		$( "#due_date" ).datepicker();
		$( "#exp_date" ).datepicker();
		
	});





-->
</script>					
</head>									
					
<body>														
				
				
<form name='invoices' method='post' action='/core/invoices.php' onsubmit='return checkdata(this)'>
  <table width='100%' border='0'>
    <tr>
      <td colspan="4" align='left' nowrap>Historial de Pagos</td>
    </tr>
    <tr>
      <td width="13%" align='left' nowrap>Tipo de Pago:</td>
      <td width="32%" align='left'>
	  <?php
	  
	  $extraitems ="<option value=''>Todos</option>";
      echo dbcombo("id_it"," concat(name,' ',code,' ',base_amount) ","invoices_type","id_it",$id_it,"name",$javascript,$extraitems);
	  ?>
	  <input type="hidden" name="id_location" id="id_location" value="<?php echo $_SESSION['session_id_location'];?>"></td>
      <td width="55%" colspan="2" align='left'>&nbsp;</td>
    </tr>
    <tr>
      <td align='left' nowrap>Desde:</td>
      <td align='left'><input type="text" name="due_date" id="due_date"></td>
      <td align='left' nowrap>Hasta: </td>
      <td align='left'><input type="text" name="exp_date" id="exp_date"></td>
    </tr>
    <tr>
      <td align='left' nowrap>&nbsp;</td>
      <td align='left'>&nbsp;</td>
      <td colspan="2" align='left'>&nbsp;</td>
    </tr>
    <tr>
      <td align='left' nowrap>&nbsp;</td>
      <td align='left' nowrap>&nbsp;</td>
      <td align='left' nowrap><input type="button" name="create_invoices" onClick="show_results()"  id="create_invoices" value="Mostrar"></td>
      <td align='left' nowrap>&nbsp;</td>
    </tr>
    <tr>
      <td align='left' colspan="4" nowrap><div id="list_layer"></div></td>
    </tr>
    <tr>
      <td align='left' colspan="4" nowrap>&nbsp;</td>
    </tr>
  </table>
</form>
					
</body></html>
<?php

	function get_locations_checkboxlist($filter){
		$cols =4;
		if($filter==''){
			$filter = 1;
		}else{
			$filter =" id_location = ".$filter;	
		}
		
		$sql ="select * from locations where $filter order by  number";
		$result = mysql_query($sql);
		if($result){
			while($row = mysql_fetch_array($result)){
				if($counter ==0){
					$data.="<tr>";
				}
				if($counter % 2 ==0){
					$bgc='#ccc';	
					$style="";	
				}else{
					$bgc='#FFF';
					$style=' border-top:1px solid #ccc';	
				}
				$data.="<td bgcolor='$bgc' style='$style'><input type='checkbox' name='id_location[]' value='".$row['id_location']."' id='r_".$row['id_location']."' ><label for='r_".$row['id_location']."'>".$row['number']."<bt>".get_residents_sumary($row['id_location'],'N')."</label></td>";
				$counter++;
				if($counter ==$cols){
					$data.="</tr>";
					$counter =0;
				}
			}//while
			return "<table border='0' width='100%' >".$data."</table>";
		}else{
			
			error_handling("get_options: ".$sql,mysql_error());
		}			
	}
?>